﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml.Linq;

namespace JSKE
{
    public class FormLang : Form
    {
        protected int DATA_MODE = Properties.Settings.Default.DataMode;
        public FormLang()
        {
            InitializeComponent();
            SetLanguage();
        }
        virtual protected void InitializeComponent()
        {
        }
        public void SetLanguage()
        {
            string filename = Properties.Settings.Default.Language;
            try
            {
                XElement root = XElement.Load("Lang\\" + filename + ".xml");
                root = root.Element(this.Name);
                SetLang(this, root);
            }
            catch (Exception)
            {
                //MessageBox.Show("Can't load language");
            }
        }
        public void SetLang(Control control, XElement root)
        {
            foreach (Control c in control.Controls)
            {
                if (string.IsNullOrEmpty(c.Text)) continue;
                Control t = c as ComboBox;
                if (t != null) continue;
                t = c as ListView;
                if (t != null) continue;

                XElement e = root.Element(c.Name);
                if (e != null)
                {
                    c.Text = root.Element(c.Name).Value;
                    SetLang(c, root);
                }
            }
        }
    }
}
